#include "golf.h"
#include <cstring>
#include <iostream>


void setgolf(golf  &g, const char * name, int hc)
{
    if (strlen(name) > Len - 1){
        std::cout << "name is too long, please <" << Len << std::endl;
        return;
    }

    strcpy_s(g.fullname, name) < 0;
    g.handicap = hc;
}

int setgolf(golf &g)
{
    using std::cin;
    using std::cout;

    cout << "please input name of golf player:" << std::endl;
    char c;
    int l = 0;
    while ((c = getchar()) != EOF)
    {
        
        if('\n' == c) {
            g.fullname[l] = '\0';
            break;
        }

        if(l >= Len - 1){
            cout << "name is too long, please < " << Len - 1 << std::endl;

            while('\n' != c) c = getchar();
            // cout << "consump left chars OVER" << std::endl;

            return 0;
        }

        g.fullname[l++] = c;
    }
    
    // cin.getline(g.fullname, Len);
    if (strcmp(g.fullname, "") == 0)
    {
        return 0;
    }
    
    cout << "please input handicap of golf player:" << std::endl;
    cin >> g.handicap;
    cin.get();

    return 1;
}

void handicap(golf & g, int hc)
{
    g.handicap = hc;
}

void showgolf(const golf & g)
{
    using std::cout;

    cout << "Name:" << g.fullname << " Handicap:" << g.handicap << std::endl;
}
